﻿/*
 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

#ifndef MULTIPLEBURNDLGFORONE_H
#define MULTIPLEBURNDLGFORONE_H

#include <QWidget>
#include "BurnCtrl/BurnCtrl.h"
#include "BurnToolCommon/Global.h"
#include "ui_MultipleBurnDlgForOne.h"

namespace BurnDlg {

class MultipleBurnDlgForOne : public QWidget {
    Q_OBJECT
public:
    explicit MultipleBurnDlgForOne(QWidget *parent = nullptr);
    ~MultipleBurnDlgForOne() override;

    int GetSelectCom() const;
    HI_BURN_FSM GetBurnFsm() const;
    void FindAndSelectString(QString target) const;
    U32 OnlyConnectHandle();
    U32 ConnectUSBHandle();
    void UpdateCmdIfIdle();
    void RefreshAllComList(QStringList &array, int index) const;
    void SetChipType(ChipType type);
    void SetAutoBurnFlag(bool isAutoNeedSet);
    void SetBootType(BootType type);
    void InitAllConfig();
    void SetReopenComFlag(bool isReopenComNeedSet);
    void SetPeriod(int periodNeedSet);
    void SetInfoArray(const QMap<int, BIN_INFO> &infoArray);
    void SetInfoArray(const QString &filePath);
    void SetSecConn(bool isSecConnNeedSet);
    void SetEraseAll(int eraseMode);
    void UpdateComSetting(UINT baudNeedSet, UINT databitsNeedSet,
                          UINT stopbitsNeedSet, QSerialPort::Parity parityNeedSet,
                          UINT flowctrlNeedSet);
    void SetForceReadFlag(bool isForceRead);
    void SetForceReadTime(UINT forceReadTimeNeedSet);
    void SetIsResetAfterSuccess(bool isResetAfterSuccessNeedSet);
    void SetYModemEachPackageSize(unsigned int modemPacketSizeBackupNeedSet);
    void SetIsSwitchAfterLoader(bool isSwitchAfterLoaderNeedSet);
    void SetConfirmConnectSleepTime(UINT time);
    void SetConfirmConnectWaitTime(UINT time);
    void SetResultByOwnerFlag(bool isResultByOwnerNeedSet);
    void SetBurnTimeout(UINT timeout);
    void SetUseExactTimer(bool useExactTimer);
    void SetIndenpendentBurn(bool indenpendentNeedSet);
    void SetIsEncrypt(bool isEncryptNeedSet);
    void SetEncryptBuffer(ENCRYPT_BUFFER encryptBufferNeedSet);
    void SetMcuConfig(McuConfig config);
    void SetChipModel(int chipModelNeedSet);
    void SetJtagSwd(McuJtagSwd config);
    void SetTransmissionMode(int tarns);
    void SetChipId(McuChipId id);
    void SetInfoStartAddress(ulong startAddr);
    void SetMainStartAddress(MainStartAddrInfo startAddrInfo);
    void SetSramAddrInfo(SramAddrInfo sainfo);
    void SetIsReadBack(bool readBack);
    void SetIsRun(bool run);
    void SetLoaderInfo(QString loaderFileNeedSet, int loaderSizeNeedSet);
    void SetParameterSaveInfo(const QString &filePath, ulong baseNum);
    void ShowResult();
    void SetResultFromAToB(unsigned int resultA, unsigned int resultB);
    unsigned int GetResult() const;
    void SetResult(unsigned int result);
    void KillAllTimer();
    void SetShutDown() const;
    U32 OnlyDisconnectHandle();
    U32 DisconnectUSBHandle();
    void SetUsbDeviceInfo(HidDeviceInfo usbDeviceInfo);
    U32 ConnectMCUHandle();
    void SlotShowLog(QString logStr, bool isShowTime, QColor color) const;
    U32 DisconnectMCUHandle();

signals:
    void SignalUpdateList();
    void SignalSendMsg(long int msgId, WPARAM wParam, LPARAM lParam);
    void SignalNotifyState(unsigned int, unsigned int);

protected:
    void InitAllCom();
    bool ConfigComPort() const;
    void SetAutoBurnFlag() const;
    void SetReopenComFlag() const;
    void SetInfoArray();
    void SetSecConn() const;
    void SetPeriod() const;
    void UpdateComSetting() const;
    void SetForceReadFlag() const;
    void SetForceReadTime() const;
    void SetIsResetAfterSuccess() const;
    void SetYModemEachPackageSize() const;
    void SetIsSwitchAfterLoader() const;
    void SetBootType() const;
    void SetResultByOwnerFlag() const;
    void SetBurnTimeout() const;
    void SetConfirmConnectSleepTime() const;
    void SetConfirmConnectWaitTime() const;
    void SetEraseAll() const;
    void SetUseExactTimer() const;
    void SetIndenpendentBurn() const;
    void SetEncryptBuffer();
    void SetIsEncrypt() const;
    void RegisteAllEdit() const;
    void SetBurnFileName();
    void SetMcuConfig();
    void SetJtagSwd();
    void SetTransmissionMode() const;
    void SetChipId();
    void SetChipModel() const;
    void SetInfoStartAddress() const;
    void SetMainStartAddress();
    void SetSramAddrInfo();
    void SetIsReadBack() const;
    void SetIsRun() const;
    void SetLoaderInfo();
    void SetParameterSaveInfo();

protected slots:
    void SlotInsertPlainText(const QString &editStr) const;
    void SlotMergeCurrentCharFormat(const QTextCharFormat &fmt) const;
    void SlotSetProgressValue(unsigned int progress) const;
    void SlotOpenComFail();
    void SlotCbnSetfocusComboCom();

private:
    Ui::MultipleBurnDlgForOne *ui;
    BurnCtrl *burnCtrl;
    ChipType chipType;
    bool isAuto;
    bool isReopenCom;
    BootType bootType;
    int isEraseMode;
    bool isSecConn;
    int period;
    UINT baud;
    UINT databits;
    UINT stopbits;
    QSerialPort::Parity parity;
    UINT flowctrl;
    UINT forceReadTime;
    QMap<int, BIN_INFO> binInfoArray;
    bool isForceReadWithSleep;
    UINT connectConfirmSleepTimeout;
    UINT connectConfirmWaitTimeout;
    bool indenpendent;
    QString strFilePath;
    bool isResultByOwner;
    UINT sendBurnTimeout;
    bool isExactTimer;
    bool isComOpenFile;
    bool isResetAfterSuccess;
    unsigned int modemPacketSizeBackup;
    bool isSwitchAfterLoader;
    bool isEncrypt;
    ENCRYPT_BUFFER encryptBuffer;
    HidDeviceInfo deviceInfo;
    MyStringClass::StringClass stringClass;
    McuConfig mcuConfig;
    McuJtagSwd jtagSwd;
    int transmissionMode;
    McuChipId chipId;
    int chipModel;
    ulong infoStartAddress;
    MainStartAddrInfo mainStartAddrInfo;
    SramAddrInfo sramAddrInfo;
    bool isReadBack;
    bool isRun;
    QString loaderFile;
    int loaderSize;
    QString parameterFilePath;
    ulong eraseBaseNum;
};

}
#endif // MULTIPLEBURNDLGFORONE_H
